/*
 * Copyright (c) 2018-2999 九五云信息科技有限公司 All rights reserved.
 *
 * https://www.gz-yami.com/
 *
 * 未经允许，不可做商业用途！
 *
 * 版权所有，侵权必究！
 */

package com.yami.shop.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yami.shop.bean.model.OrderItem;
import com.yami.shop.bean.param.PayTopParam;
import com.yami.shop.bean.param.ProdAnalysisSurveyParam;
import com.yami.shop.common.util.PageParam;
import com.yami.shop.dao.OrderItemMapper;
import com.yami.shop.service.OrderItemService;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 *
 * @author lgh on 2018/09/15.
 */
@Service
public class OrderItemServiceImpl extends ServiceImpl<OrderItemMapper, OrderItem> implements OrderItemService {

    @Autowired
    private OrderItemMapper orderItemMapper;

	@Override
	public List<OrderItem> getOrderItemsByOrderNumber(String orderNumber, Integer lang) {
		return orderItemMapper.listByOrderNumber(orderNumber,lang);
	}

    @Override
    public IPage<PayTopParam> getPayAmounts(PageParam<OrderItem> page, ProdAnalysisSurveyParam param, Integer dbLang) {
        IPage<PayTopParam> resPage = orderItemMapper.getPayAmounts(page, param, dbLang);
//        List<PayTopParam> payAmounts = resPage.getRecords();
//        if (CollectionUtils.isEmpty(payAmounts)) {
//            return resPage;
//        }
//        List<PayTopParam> list = new ArrayList<>();
//        Long shopId = param.getShopId();
//        for (PayTopParam payAmount : payAmounts) {
//            payAmount = orderItemMapper.getPayAmount(payAmount.getProdId(),shopId);
//            list.add(payAmount);
//        }
//        resPage.setRecords(list);
	    return resPage;
    }

    @Override
    public Integer getPayPersonNumByParam(Integer prodId,Long shopId, Date startTime, Date endTime) {
	    return orderItemMapper.getPayPersonNumByParam(prodId,shopId,startTime,endTime);
    }

    @Override
    public void insertBatchOrderItem(List<OrderItem> orderItems) {
        saveBatch(orderItems);
        orderItemMapper.insertBatchOrderItemLang(orderItems);
    }


//    @Override
//    public List<OrderItem> getUnCloseRefundOrderItemByOrderNumber(String orderNumber) {
//	    return orderItemMapper.getUnCloseRefundOrderItemByOrderNumber(orderNumber);
//    }

}
